﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MicropleSoft.Common.Library
{
    public class StringUtil
    {
        /// <summary>
        /// 连接字符串
        /// </summary>
        /// <param name="list"></param>
        /// <param name="connector"></param>
        /// <returns></returns>
        public static string Concat(List<string> list, string connector )
        {
            string result = string.Empty;
            for (int idx = 0; idx < list.Count;idx++ )
            {
                if(idx == 0)
                {
                    result = list[idx];
                }
                else
                {
                    result += (connector + list[idx]);
                }
            }
            return result;
        }

        /// <summary>
        /// 连接字符串
        /// </summary>
        /// <param name="enumerable"></param>
        /// <param name="connector">连接器</param>
        /// <returns></returns>
        public static string Concat(IEnumerable<String> enumerable, string connector)
        {
            return Concat(enumerable.ToList(),connector);
        }

        /// <summary>
        /// 连接字符串
        /// </summary>
        /// <param name="list"></param>
        /// <param name="connector"></param>
        /// <returns></returns>
        public static string Concat(List<SingleValue> list, string connector)
        {
            var tempList = list.Select(singleValue => singleValue.Value).ToList();
            return Concat(tempList, connector);
        }
    }
}
